﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SqlMonitoring.Core.Logging;
using SqlMonitoring.Agent.AgentServiceBase;

namespace SqlMonitoring.Agent
{
    public class MainService
    {        
        public MainService()
        {
            Log = new Logging();
        }

        public void Init()
        {            
            AgentManager.SingleInstance.Log = Log;
            AgentManager.SingleInstance.Agents = new List<IAgent>() { new Windows2003(), new Performance() };
            AgentManager.SingleInstance.Configure();
            AgentManager.SingleInstance.Start();
        }

        private Logging Log { get;  set; }

        internal void MinuteChecks(object state)
        {
            // This class will fire every minute. This will be used to check for items that are not event driven.
            Log.Info("Starting minute check");
            foreach (var agent in AgentManager.SingleInstance.Agents)
            {
                Log.Info(String.Format("Testing agent \"{0}\".", agent));
                if (!agent.IsRunning)
                {
                    Log.Warn(String.Format("Agent \"{0}\" is not Running. Trying to restart.", agent));

                    continue;
                }
                else
                {
                    Log.Info(String.Format("Agent \"{0}\" apears to be Running, nothing to do.", agent));
                }
            }
        }
    }
}
